package com.limingru.newbee.util;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class BeanUtil {
    public static <T> List<T> copyList(List source, Class<T> clazz) {
        List<T> targetList = new ArrayList<T>();
        if (source != null) {
            try {
                for (Object o : source) {
                    T target = clazz.newInstance();
                    BeanUtils.copyProperties(o, target);
                    targetList.add(target);
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            }
        }
        return targetList;
    }
}
